FROM repo.seres.cn/anapsix/alpine-java:8_server-jre_unlimited

MAINTAINER brx@enlong.cn
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 设置构建环境变量
ENV NODE_OPTIONS="--max-old-space-size=4096"
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

# 定义变量并设置默认值（可在构建时覆盖）
ARG SERVICE_PATH="brx-gateway"



ENV XM=""
#当前jarfile
ENV JAR_FILE=''

#端口
ENV EXPOSE_PORT=''
ENV LOCALHOST_HOST=''

#redis 地址
ENV REDIS_HOST=''
ENV REDIS_PORT=''
ENV REDIS_PASSWORD=''
ENV REDIS_DATABASE=''

#nacos 地址
ENV NACOS_HOST=''
ENV NACOS_PORT=''
ENV NACOSNAMESPACE=''
ENV NACOS_USERNAME=''
ENV NACOS_PASSWORD=''

#plumelog
ENV PLUMELOGENABLED=''
ENV PLUMELOGHOST=''
ENV PLUMELOGMODEL=''
ENV PLUMELOGREDISHOST=''
ENV PLUMELOGREDISPORT=''
ENV PLUMELOGREDISPASSWORD=''
ENV PLUMELOGREDISDB=''
ENV PLUMELOGKAFKAHOSTS=''
ENV PLUMELOGKAFKAGROUPNAME=''

#xxljob
ENV XXLJOBEXECUTORADDRESS=''
ENV XXLJOBACCESSTOKEN=''
ENV XXLJOBEXECUTORAPPNAME=''
ENV XXLJOBEXECUTORIP=''
ENV XXLJOBEXECUTORPORT=''

#OSS
ENV OSS_BUCKET_NAME=''
ENV OSS_TYPE=''
ENV OSS_TARGET=''
ENV OSS_LINK=''
ENV OSS_ENDPOINT=''
ENV OSS_ACCESS_KEY=''
ENV OSS_SECRET_KEY=''
ENV OSS_TYPE_WHITE='.png,.jpg,.zip,.rar,.7z,.gz,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.mp4,.JPGE,.jpge'

#
ENV DBHOST=''
ENV DBPORT=''
ENV DBNAME=''
ENV DBUSERNAME=''
ENV DBPWD=''

ENV PROFILES=''

# 通用环境变量
ENV COMMON_ENV=''

ENV PROJECT_NAME=''
ENV MANAGEMENT_SERVER_PORT=''

#jasypt 加密
ENV JC_JASYPT_ENCRYPTOR_PASSWORD=''
#key
ENV JC_AUTH_K=''
ENV JC_AUTH_KEY=''
ENV JC_AUTH_N=''

RUN mkdir -p /app

WORKDIR /app

EXPOSE 8810

COPY ./${SERVICE_PATH}.jar .
COPY ./Start.sh .
COPY ./java.pem .
COPY ./JK-S-PKI01-CA.crt .
COPY ./JK-S-PKI02-CA.crt .

# 创建存放证书的目录 
RUN mkdir -p /usr/local/share/ca-certificates/ 

# 尝试复制证书文件（如果存在）
RUN cp ./java.pem /usr/local/share/ca-certificates/ 2>/dev/null || echo "java.pem 不存在，跳过证书复制"

RUN cp ./JK-S-PKI01-CA.crt /usr/local/share/ca-certificates/ 2>/dev/null || echo "JK-S-PKI01-CA.crt 不存在，跳过证书复制"

RUN cp ./JK-S-PKI02-CA.crt /usr/local/share/ca-certificates/ 2>/dev/null || echo "JK-S-PKI02-CA.crt 不存在，跳过证书复制"



# 判断是否存在证书文件，若存在则更新系统证书
RUN if [ -f /usr/local/share/ca-certificates/java.pem ]; then \
        echo "✅ 检测到证书文件，正在更新系统证书..." && \
        update-ca-certificates; \
    else \
        echo "ℹ️ 未检测到证书文件，跳过更新系统证书"; \
    fi

# 查找并重命名第一个找到的JAR文件为 app.jar
RUN find /app -type f -name "brx-key.jar" -exec rm -f {} + \
    && find /app -type f -name "*.jar" -exec mv {} app.jar \; \
    && find /app -name "pom.xml" -exec rm -f {} + \
    && [ -d "/app/src" ] && rm -rf /app/src \
    || echo "清理操作完成"

RUN mkdir -p /app/brx/log && \
    chmod -R 755 /app/brx/log

ENTRYPOINT ["sh","./Start.sh"]